#define _CRT_SECURE_NO_WARNINGS 1
#include <stdio.h>

struct ListNode {
    int val;
    struct ListNode* next;   
};
typedef struct ListNode ListNode;
struct ListNode* ReverseList(struct ListNode* pHead) {
    // write code here
    if (pHead == NULL || pHead->next == NULL)
        return pHead;
    ListNode* newHead = NULL;
    ListNode* cur = pHead;
    ListNode* next = pHead->next;
    while (cur)
    {
        cur->next = newHead;
        newHead = cur;
        cur = next;
        if (next)
            next = next->next;
    }
    return newHead;
}